//#define __DEBUG__
// by Tyrghen
#define THIS_FILE "fn_keydown_handler.sqf"
#include "x_setup.sqf"

private["_handled", "_ctrl", "_dikCode", "_shift", "_ctrlKey", "_alt"];
_ctrl = _this select 0;
_dikCode = _this select 1;
_shift = _this select 2;
_ctrlKey = _this select 3;
_alt = _this select 4;
_handled = false;
__TRACE_1("_this","_this")
if (_dikCode in actionKeys "TeamSwitch") then {
	// TYRGHEN - We check if my menu is actived, if not, then we default to the Domination menus
	if (isNil "TYR_MENU_IsActive" || {TYR_MENU_IsActive <= 0}) then {
		if ((alive player) && !(player getVariable "xr_pluncon") && !(_shift) && !(_ctrlKey) && !(_alt)) then {
			[0, _this] call FUNC(KeyDownCommandingMenu);
			_handled = true;
		};
	};
};
if (_dikCode in actionKeys "GetOver") then {	
	if ((alive player) && !(player getVariable "xr_pluncon") && (!_shift && !_ctrlKey && !_alt)) then {
		[] spawn {
			if (dialog) then { closeDialog 0; };
			sleep 1;
			if (commandingMenu != "") then {
				showCommandingMenu "RscMainMenu";
			};
			GVAR(commandingMenuIniting) = false;
			GVAR(DomCommandingMenuBlocked) = false;
			sleep 1;
			showCommandingMenu "";
			diag_log format["keydown_handler %1 %2",_this,[dialog,GVAR(DomCommandingMenuBlocked),GVAR(commandingMenuIniting),commandingMenu]];
		};
		_handled = false;
		showChat true;
		// TYRGHEN - Fix for bugged Chestbag
		if (!(isNil "FSFSV_CallBackpackToFront")) then {
			if (isForcedWalk player && {(isNull(player getVariable ["FSFSV_BACKPACK",objNull]) || {((attachedObjects player) find ((player getVariable ["FSFSV_BACKPACK",objNull])) ) < 0})}) then {
				player forceWalk false;
			};
		};
	};
};
__TRACE_1("_handled","_handled")
_handled;